﻿// ===============================================================================
// IThreadStorage.cs
// EOS Framework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Contracts.ThreadStorage
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using Microsoft.Practices.ServiceLocation;

    /// <summary>
    /// Simple wrapper around the common service locator, which 
    /// allocates one instance of the requested type per thread.
    /// </summary>
    public interface IThreadStorage
    {
        /// <summary>
        /// Initializes the storage with the specified service locator.
        /// </summary>
        /// <param name="serviceLocator">The service locator. Cannot be null
        /// (Nothing in Visual Basic).</param>
        /// <exception cref="ArgumentNullException"><paramref name="serviceLocator"/>
        /// is null (Nothing in Visual Basic).</exception>
        void Initialize(IServiceLocator serviceLocator);

        /// <summary>
        /// Creates a new instance with the specified type, if it does
        /// not exist for this thread, otherwise it returns a new instance.
        /// </summary>
        /// <typeparam name="TType">The of the requested instance.</typeparam>
        /// <returns>An instance of the specified type.</returns>
        [SuppressMessage("Microsoft.Design", "CA1004")]
        TType CreateInstance<TType>();

        /// <summary>
        /// Creates a new instance with the specified type, which was
        /// registered at the service locator with the specified name, if it does
        /// not exist for this thread, otherwise it returns a new instance.
        /// </summary>
        /// <typeparam name="TType">The of the requested instance.</typeparam>
        /// <param name="name">The name of the instance. Cannt be null or empty
        /// and cannot not contains only blanks.</param>
        /// <returns>An instance of the specified type.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="name"/>
        /// is null (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="name"/> is empty
        /// or contains only blanks.</exception>
        [SuppressMessage("Microsoft.Design", "CA1004")]
        TType CreateInstance<TType>(string name);
    }
}
